package com.xxg.renrenlogin.service;

import com.alibaba.fastjson.JSON;
import com.xxg.renrenlogin.domain.result.AccessTokenResult;
import com.xxg.renrenlogin.domain.result.BaseResult;
import com.xxg.renrenlogin.domain.result.LoginReturnCodeEnum;
import com.xxg.renrenlogin.exception.WeChatException;
import com.xxg.renrenlogin.manager.wechat.WeChatManager;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;


/**
 * 微信认证接口实现
 *
 * @author xxg
 * @date 2020/9/28
 */
@Service
@AllArgsConstructor
public class WeChatServiceImpl implements WeChatService {
    private final WeChatManager weChatManager;

    @Override
    public BaseResult lpVerify(String code) {
        AccessTokenResult result;
        try {
            result = weChatManager.code2Session(code);
        } catch (WeChatException e) {
            return new BaseResult(LoginReturnCodeEnum.FAILURE, e.getMessage(), null);
        }
        return new BaseResult(result);
    }

}
